
from django_filters.rest_framework import FilterSet
from django_filters.filters import *

from apps.opoc.models import *
from django_filters.rest_framework import FilterSet

from apps.opoc.models import Opoc_InspectionRecord


class Opoc_RecordsFilter(FilterSet):
    """
    Opoc_Records过滤
    """
    add_time_begin = DateFilter(field_name="add_time",help_text="开始创建时间",lookup_expr="gte")
    add_time_end = DateFilter(field_name="add_time",help_text="结束创建时间",lookup_expr="lte")
    this_month_begin_date = DateFilter(field_name="contract_signing_begin_date",help_text="本月合同签订开始日期",lookup_expr="gte")
    next_month_begin_date  = DateFilter(field_name="contract_signing_begin_date",help_text="本月合同签订结束日期",lookup_expr="lte")
    contract_signing_end  = DateFilter(field_name="contract_signing_end_date",help_text="合同过期",lookup_expr="lt")
    contract_signing_end_10days_begin  = DateFilter(field_name="contract_signing_end_date",help_text="合同10天内即将到期",lookup_expr="gte")
    contract_signing_end_10days_end  = DateFilter(field_name="contract_signing_end_date",help_text="合同10天内即将到期",lookup_expr="lte")
    insurance_invalid  = DateFilter(field_name="insurance_invalid_date",help_text="保险过期",lookup_expr="lt")
    insurance_invalid_10days_begin  = DateFilter(field_name="insurance_invalid_date",help_text="保险10天内即将到期开始",lookup_expr="gte")
    insurance_invalid_10days_end  = DateFilter(field_name="insurance_invalid_date",help_text="保险10天内即将到期结束",lookup_expr="lte")
    #certificate_holding  = BooleanFilter(field_name="certificate_holding",help_text="持证情况",lookup_expr="contains")
    class Meta:
        model = Opoc_Records
        fields = ['company','status','is_effective','labor_service_unit','add_time_begin','add_time_end',
                  'this_month_begin_date','next_month_begin_date',
                  'contract_signing_end','contract_signing_end_10days_begin','contract_signing_end_10days_end',
                  'insurance_invalid','insurance_invalid_10days_begin','insurance_invalid_10days_end',
                  'filled_by']


class Opoc_Certificate_ImgsFilter(FilterSet):
    """
    一人一码个人证书Img过滤
    """
    add_time_begin = DateFilter(field_name="add_time",help_text="开始创建时间",lookup_expr="gte")
    add_time_end = DateFilter(field_name="add_time",help_text="结束创建时间",lookup_expr="lte")
    class Meta:
        model = Opoc_Certificate_Imgs
        fields = ['type','add_time_begin','add_time_end','filled_by']


class Opoc_Common_PdfsFilter(FilterSet):
    """
    opoc公共pdf过滤
    """
    add_time_begin = DateFilter(field_name="add_time",help_text="开始创建时间",lookup_expr="gte")
    add_time_end = DateFilter(field_name="add_time",help_text="结束创建时间",lookup_expr="lte")
    class Meta:
        model = Common_Pdfs
        fields = ['type','add_time_begin','add_time_end','filled_by']

class Opoc_InspectionRecordsFilter(FilterSet):
    """
    opoc检查记录过滤
    """
    company = NumberFilter(field_name="opoc_record__company__id",help_text="公司")
    add_time_begin = DateFilter(field_name="created_at",help_text="开始创建时间",lookup_expr="gte")
    add_time_end = DateFilter(field_name="created_at",help_text="结束创建时间",lookup_expr="lte")
    class Meta:
        model = Opoc_InspectionRecord
        fields = ['company','add_time_begin','add_time_end']


class Opoc_Labor_service_unitsFilter(FilterSet):
    """
    opoc劳务单位过滤
    """
    add_time_begin = DateFilter(field_name="add_time",help_text="开始创建时间",lookup_expr="gte")
    add_time_end = DateFilter(field_name="add_time",help_text="结束创建时间",lookup_expr="lte")
    class Meta:
        model = Labor_service_unit
        fields = ['add_time_begin','add_time_end','filled_by']



__all__ =[
    'Opoc_RecordsFilter',
    'Opoc_Common_PdfsFilter',
    'Opoc_Labor_service_unitsFilter',
    'Opoc_Certificate_ImgsFilter',
]
